package tau.pimpmyfreedb.master;

import org.eclipse.swt.widgets.Shell;

import tau.pimpmyfreedb.GUI.SWTUtil;

public abstract class GuiCallback<T> extends Callback<T>
{
	private final Shell returnTo;

	public GuiCallback()
	{
		this(null);
	}
	
	public GuiCallback(Shell returnTo)
	{
		this.returnTo = returnTo;
	}

	@Override
	public void execute(final T param) {
		SWTUtil.getDisplay().asyncExec(new Runnable()
		{
			@Override
			public void run() {
		guiExecute(param);
				if (getReturnTo() != null)
				{
					getReturnTo().setEnabled(true);
					getReturnTo().setFocus();
				}
			}
		});
	}

	public abstract void guiExecute(T param);

  public Shell getReturnTo() {
    return returnTo;
  }
}
